package com.yuexunit.operationman.nbsy.module.OperationInventory.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationInventory.adapter.EditInventoryAdapter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.bean.InventoryBean;
import com.yuexunit.operationman.nbsy.widget.FixedSwipeListView;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/8/15 0015.
 */

public class Act_OperationInventory_EditList extends BaseKJActivity {

    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.search_txt)
    EditText searchTxt;
    @Bind(R.id.listview)
    FixedSwipeListView listview;

    EditInventoryAdapter adapter;
    ArrayList<InventoryBean.ObjectEntity.CheckItemListEntity> list = new ArrayList<>();

    @Override
    public void setRootView() {
        setContentView(R.layout.act_operationinventory_list);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        setTitle();
        list =(ArrayList<InventoryBean.ObjectEntity.CheckItemListEntity>) getIntent().getExtras().get("goods");
        adapter = new EditInventoryAdapter(listview, list, R.layout.item_operationinventory_edit);
        listview.setAdapter(adapter);
        searchTxt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (adapter != null) {
                    adapter.getFilter().filter(s.toString());
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientName());
        if (AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.INVENTORYBEAN.getObject().getCheck().getInHospitalNo());
        tvPatientDisease.setText(PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_DISEASE));
    }


    @OnClick({R.id.titlebar_docadvice_img_back, R.id.sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.sure:
                Bundle bundle =new Bundle();
                bundle.putSerializable("goods",adapter.getGoodsValue());
                Intent mIntent = new Intent();
                mIntent.putExtras(bundle);
                setResult(101, mIntent);
                finish();
                break;
        }
    }
}
